<?php

require_once("finefs/class.FineFS.php");
require_once("finefs/utils/except.ApplicationException.php");
require_once("finefs/utils/except.IOException.php");
require_once("class.FineDBCollection.php");
require_once("class.FineDBDocument.php");

/**
 * Minimal object for the management of FineDB's document.
 *
 * @author	Amaury Bouchard <amaury.bouchard@finemedia.fr>
 * @copyright	Copyright (c) 2010, FineMedia
 * @package	FineDB
 * @subpackage	lib
 * @version	$Id: class.FineDBProtoDocument.php 8 2011-09-26 10:38:52Z amaury.bouchard $
 */
class FineDBProtoDocument extends FineDBDocument {
	/* *********************** DOCUMENT MANAGEMENT METHODS ******************* */
	/**
	 * Returns the collection this document belongs to.
	 * @return	FineDBCollection	Document's collection.
	 */
	public function getCollection() {
		return ($this->_getCollection);
	}
	/**
	 * Returns the identifer of the current document.
	 * @return	string	Document's identifier.
	 */
	public function getId() {
		return ($this->_getId());
	}
	/**
	 * Save the current document.
	 * @throws	ApplicationException	If this document was removed already.
	 * @throws	IOException		Data writing error.
	 */
	public function save() {
		$this->_save();
	}
	/**
	 * Remove the current document.
	 * @throws	ApplicationException	If this document was removed already.
	 * @throws	IOException		Data writing error.
	 */
	public function _remove() {
		$this->_remove();
	}

	/* *********************** METADATA MANAGEMENT METHODS ******************* */
	/**
	 * Returns the value of a metadata, or the full list of metadata.
	 * @param	string	$name	Metadata's name.
	 * @return	string	Metadata value.
	 * @throws	ApplicationException	If this document was removed already.
	 */
	public function getMeta($name=null) {
		return ($this->_getMeta($name));
	}
	/**
	 * Modify a metadata.
	 * @param	string	$name	Metadata's name.
	 * @param	string	$value	Metadata's value.
	 * @throws	ApplicationException	If this document was removed already.
	 */
	public function setMeta($name, $value) {
		$this->_setMeta($name, $value);
	}

	/* *********************** DATA MANAGEMENT METHODS ******************* */
	/**
	 * Returns document's data.
	 * @return	mixed	Document's data.
	 * @throws	ApplicationException	If this document was already removed.
	 */
	public function getData() {
		return ($this->_getData());
	}
	/**
	 * Returns a document's datum.
	 * @param	string	$key	(optional) Name of the first-level data key.
	 * @return	mixed	Document's datum.
	 * @throws	ApplicationException	If this document was already removed.
	 */
	public function getDatum($key) {
		return ($this->_getDatum($key));
	}
	/**
	 * Modify document's data.
	 * @param	mixed	$data	The whole redefined data set.
	 * @throws	ApplicationException	If this document was already removed.
	 */
	public function setData($data) {
		$this->_setData($data);
	}
	/**
	 * Modify a document's datum.
	 * @param	mixed	$key	The name of the first-level data key.
	 * @param	mixed	$data	(optional) The data to defined. Leave it null to remove the key.
	 * @throws	ApplicationException	If this document was removed already.
	 */
	public function setDatum($key, $data=null) {
		$this->_setDatum($key, $data);
	}
}

?>
